#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 10;
int n;
int st[N];
bool used[N];

void dfs(int m)
{
    if (m > n)
    {
        for (int i = 1; i <= n; ++i)
            printf("%d ", st[i]);
        puts("");

        return;
    }

    for (int i = 1; i <= n; ++i)
        if (!used[i])
        {
            st[m] = i;
            used[i] = true;
            dfs(m + 1);

            used[i] = false;
        }
}

int main()
{
    scanf("%d", &n);

    dfs(1);

    return 0;
}